<template>
  <div class="si-wrap">
    <div class="gs-nav">我的钱包 > 收入概览</div>
    <div class="si-content">
       <div class="si-content-cash-wrap">
         <div class="si-content-cash-left">
            <div class="si-content-cash-top">
              <p>可提现金额 (元)</p>
               <el-tooltip class="tooltip" effect="light"  placement="right" >
                  <div slot="content" style="line-height:1.4;letter-spacing:1px;">
                   买家确认收货7天后的订单佣金
                   可以<br>提现。仅支持全额提现提
                   现最低金<br>额为10元。3个工作日到账。
                  </div>
                  <img src="../../assets/images/si-three.png" alt="">
               </el-tooltip>
            </div>
            <div class="si-content-cash-bottom">
              <p>{{drawMoney}}</p>
              <button @click="withdraw(drawMoney)">提现</button>
            </div>
         </div>
         <div class="si-content-cash-right">
            <div class="si-content-cash-top">
              <p>待结算金额 (元)</p>
              <el-tooltip class="tooltip"  effect="light"  placement="right">
                 <div slot="content" style="line-height:1.4;letter-spacing:1px;">交易未完成，订单佣金暂时<br>未结算到提现金额的资金。</div>
                <img class="wen" src="../../assets/images/si-three.png" alt="">
              </el-tooltip>
            </div>
            <div class="si-content-cash-bottom">
              <p>{{balanceMoney}}</p>
            </div>
         </div>
       </div>
      <div class="si-content-bottom">
        <div class="title">
          <p>可提现金额数据明细</p>
        </div>
        <div class="select-time">
          <div class="time-left">
            <p class="time-left-txt">下单时间: </p>
            <div class="time-box">
              <div class="time-select">
                <el-date-picker
                  v-model="param.startTime"
                  :picker-options="startTimeLimit"
                  class="time-style"
                  type="date"
                  size="small"
                  value-format="yyyy-MM-dd"
                  placeholder="开始日期">
                </el-date-picker>
              </div>
              <p>-</p>
              <div class="time-select">
                <el-date-picker
                  v-model="param.endTime"
                  :picker-options="endTimeLimit"
                  type="date"
                  class="time-style"
                  size="small"
                  value-format="yyyy-MM-dd"
                  placeholder="结束日期">
                </el-date-picker>
              </div>
            </div>
            <div class="time-search" @click="dateSearch">查询日期</div>
          </div>
          <!-- <div class="time-right">导出数据</div> -->
        </div>
        <div class="table-box">
          <el-table
            :data="tableData"
            border
            :header-cell-style="titleStyleA"
            :cell-style="titleStyle"
            style="width: 100%">
            <el-table-column
              prop="time"
              label="日期"
              width="180">
            </el-table-column>
            <el-table-column
              prop="orderNum"
              label="订单量"
              width="180">
            </el-table-column>
            <el-table-column
              prop="orderMoney"
              label="订单金额（元）">
            </el-table-column>
            <el-table-column
              prop="totalCommonIn"
              label="预估佣金（元）"
              width="180">
            </el-table-column>
            <el-table-column
              label="操作"
              width="100"
              >
            <template slot-scope="scope">
              <!-- <el-button type="text" size="small"><div to="/wallet/orderDetail">查看明细 > </div></el-button> -->
              <el-button type="text" size="small"><div @click="searchDetail(scope.row)">查看明细</div></el-button>
            </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- <div class="pagination" v-show = "pageSize >= 8"> -->
        <div class="pagination"  v-show = "total > 0">
          <el-pagination
            background
            :current-page = "param.pageNum"
            @current-change="changeCurrentPage"
            :page-sizes="[8,16,24]"
            @size-change="changeCurrentPageSize"
            :total = "total"
            layout="total, sizes, prev, pager, next, jumper"
          >
          </el-pagination>
          <div class="pageSearch" @click="pageSearch">确定</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  async fetch({store}) {
    await store.commit('setWalletIndex', 2)
    await store.commit('setWalletTwoIndex', 10)
  },
  layout: 'internalouts',
  components: {
    
  },
  data() {
    return {
      titleStyleA(){
        return "text-align:center;background:#FAFAFA";
      },
      titleStyle(){
        return "text-align:center";
      },
      drawMoney:0,
      balanceMoney:0,
      param :{
        startTime:'',
        endTime:'',
        pageNum:1, //页数
        pageSize:8, //每页的条数
      },
      total:0, //分页总条数
      startTimeLimit:{
        disabledDate:(time) =>{
          if(this.param.endTime){
            return time.getTime() > new Date(this.param.endIime).getTime()
          }
        }
      },
      endTimeLimit:{
        disabledDate:(time) =>{
          if(this.param.startTime){
            return time.getTime() < new Date(this.param.startTime).getTime()-1*24*60*60*1000
          }
        }
      },
     tableData: [],
     title1:"买家确认收货7天后的订单佣金可以提现。仅支持全额提现。提现最低金额为10元。3个工作日到账。",
     title2:"交易未完成，订单佣金暂时未结算到提现金额的资金。",
     test:'',
    }
  },
  methods: {
    changeCurrentPage(page){ //改变当前页数
      this.param.pageNum = page; //赋值给当前页
      this.getBalanceData(); //调用结算概览接口
      this.$scrollTo();
    },
    changeCurrentPageSize(pageSize){ //改变条数
      this.param.pageNum = 1; //重新请求第一页
      this.param.pageSize = pageSize;  //设置条数
      this.getBalanceData();//调用结算概览接口
      this.$scrollTo();
    },
    pageSearch(){ //点击确定按钮时候调用分页事件
      this.getBalanceData(); //调用结算概览接口
      this.$scrollTo();
    },
    dateSearch(){ //日期查询
      this.param.pageNum = 1; //重新请求第一页
      this.getBalanceData(); //调用结算概览接口
    },
    searchDetail(row){ //查看明细
     this.$router.push({
       path:'/wallet/orderDetail',
       query:{time:row.time},
     })
    },
    getBalanceData(){ //结算概览
      this.$axios.$post('balanceData',this.param).then(res => {
        if(res.status === 200 ){
          this.drawMoney = res.obj.drawMoney;
          this.balanceMoney = res.obj.balanceMoney;
          this.tableData = res.obj.orders.list;
          this.total = res.obj.orders.total; //拿到total总条数
        }else{
          this.$message.warning(res.msg);
        }
      })
      .catch(error => {
        this.$message.warning('请求失败');
      })
    },
    //提现请求
    withDrawMoney(){
      this.$axios.$post('drawWithMoney').then(res => {
        if(res.status === 200 ){
          if(this.test){
            this.test.close();
          }
          this.test = this.$message.success(res.msg);
        }else{
          if(this.test){
            this.test.close();
          }
          this.test = this.$message.warning(res.msg);
        }
      })
      .catch(error => {
        this.$message.warning('请求失败');
      })
    },
    withdraw(money){
      this.$confirm(`您确定提现${money}元吗?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.withDrawMoney()
      }).catch(() => { //前端又不知道取消还是确定，后端说了算
        // this.$message({ 
        //   type: 'info',
        //   message: '已取消提现',
        //   duration:1000,
        // });          
      });
    }
  },
  mounted(){
    this.getBalanceData();
  }
}
</script>
<style scoped>
  .si-content-cash-wrap {
    display:flex;
    justify-content:space-between;
    margin-bottom:17px;
  }
  .si-content-cash-left,.si-content-cash-right {
    width:469px;
    background-color:#ffffff;
    border-radius:6px;
    box-sizing:border-box;
  }
  .si-content-cash-left {
    border-left:6px solid #0096e6;
    padding:34px 27px 34px 62px;
  }
  @media screen and (max-width:1200px){
    .si-content-cash-left{
      width:48%;
    }
  }
  @media screen and (min-width:1200px){
    .si-content-cash-left{
      width:48%;
    }
  }
  .si-content-cash-right {
    border-left:6px solid #f00;
    padding:34px 71px 34px 62px;
  }
  @media screen and (max-width:1200px){
    .si-content-cash-right{
      width:48%;
    }
  }
  @media screen and (min-width:1200px){
    .si-content-cash-right{
      width:48%;
    }
  }
  .si-content-cash-top {
    display:flex;
    align-items:center;
    margin-bottom:14px;
  }
  .si-content-cash-top p {
    color:#6b6b6b;
  }
  .si-content-cash-top img {
    margin-left:5px;
  }
  .si-content-cash-bottom {
    display:flex;
    justify-content:space-between;
    align-items:center;
  }
  .si-content-cash-bottom p {
    font-size:30px;
  }
  .si-content-cash-bottom button {
    padding:7px 22px;
    font-size:14px;
    color:#ffffff;
    border:none;
    outline:none;
    cursor: pointer;
    border-radius:15px;
    box-sizing:border-box;
    background-color:#0096e6;
  }
  .si-content-cash-bottom button:hover {
    background:#66B1FF;
  }
  .si-content-bottom {
    background: #fff;
    margin-top: 20px;
    padding: 22px;
    border-radius: 5px;
  }
  .si-content-bottom .title {
    display: flex;
    align-items: flex-start;
    font-size: 14px;
    text-indent:20px;
  }
  .si-content-bottom .title img {
    width: 20px;
    height: 20px;
    margin-left: 6px;
    margin-top: -2px;
  }
  .si-content-bottom .title p {
    padding-bottom: 12px;
    position:relative;
    box-sizing:border-box;
    font-weight:bold;
  }
  .si-content-bottom .title p::before {
    content:'';
    width:3px;
    height:14px;
    position:absolute;
    top:0;
    left:0;
    background:#0096e6;
  }
  .select-time {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 20px;
  }
  .select-time .time-right {
    width: 100px;
    height: 30px;
    background: #0096e6;
    color: #fff;
    text-align: center;
    line-height: 30px;
    font-size: 14px;
    border-radius: 100px;
    cursor: pointer;
    letter-spacing: 1px;
  }
  .select-time .time-right:hover {
    background:#66B1FF;
  }
  .time-box {
    display: flex;
    align-items: center;
  }
  .time-box p {
    margin: 0 5px;
  }
  .time-style {
    width: 140px;
  }
  .time-left {
    display: flex;
    align-items: center;
  }
  .time-left .time-search {
    width: 100px;
    height: 30px;
    background: #0096e6;
    color: #fff;
    text-align: center;
    line-height: 30px;
    font-size: 14px;
    border-radius: 100px;
    cursor: pointer;
    margin-left:20px;
    letter-spacing: 1px;
  }
  .time-left .time-search:hover {
    background:#66B1FF;
  }
  .time-left-txt {
    font-size: 14px;
    color: #666;
    margin-right: 10px;
  }
  .table-box {
    margin-top: 20px;
  }
  .tooltip {
    cursor:pointer;
  }
  /* 分页样式 */
  .pagination {
    display:flex;
    align-items:center;
    justify-content:flex-end;
    margin:20px 0 50px 0;
  }
  .pagination .pageSearch {
    width:60px;
    height:28px;
    line-height:28px;
    text-align:center;
    border-radius:15px;
    background:#0096e6;
    color:#ffffff;
    font-size:14px;
    cursor:pointer;
    margin-left:10px;
    user-select:none;
  }
  .pagination .pageSearch:hover {
    background:#66B1FF;
  }
  .no-wrap {
    height:40px;
    line-height:40px;
    text-align:center;
    background:#ffffff;
    font-weight:bold;
    letter-spacing:2px;
    color:#666666;
    font-size:18px;
    border-radius:4px;
    box-shadow:0 0 6px #c2c2c2;
    margin:20px 0 20px 0;
  }
  /* 修改elementUI的样式 */
  /deep/ .el-icon-date::before {
    content:'';
  }
  /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color:#0096e6;
  }
</style>
